import { setStorageSync, getStorageSync, removeStorageSync } from '@tarojs/taro';

/**
 *  设置传播人fromUid
 * @type {string}
 */
export const setFromUid = (fd: any, scenes: any = {}) => {
  let selfd = fd;
  if (!fd && scenes.fd) {
    selfd = scenes.fd;
  }
  if (!selfd) {
    return;
  }
  return setStorageSync('FROM_UID', selfd);
};

/**
 *  设置传播人fromUid
 * @type {string}
 */
export const getFromUid = () => {
  return getStorageSync('FROM_UID');
};

/**
 *  删除传播人fromUid
 * @type {string}
 */
export const removeFromUid = () => {
  return removeStorageSync('FROM_UID');
};

/**
 *  设置传播人fromUid
 * @type {string}
 */
export const setId = (id: any, scenes: any = {}) => {
  let selfid = id;
  if (!id && scenes.id) {
    selfid = scenes.id;
  }
  if (!selfid) {
    return;
  }
  return setStorageSync('ID', selfid);
};

/**
 *  设置传播人fromUid
 * @type {string}
 */
export const getId = () => {
  return getStorageSync('ID');
};

/**
 *  删除传播人fromUid
 * @type {string}
 */
export const removeId = () => {
  return removeStorageSync('ID');
};

/**
 *  设置小程序 进入场景值
 * @type {string}
 */
export const setScene = (scene: string) => {
  if (!scene) {
    return;
  }
  return setStorageSync('SCENE', scene);
};

/**
 *  设置用户本地openid
 * @type {string}
 */
export const setOpenId = (openid: string) => {
  if (!openid) {
    return;
  }
  return setStorageSync('OPENID', openid);
};

/**
 *  获取本地openid
 * @type {string}
 */
export const getOpenId = () => {
  return getStorageSync('OPENID');
};

/**
 *  设置用户本地token
 * @type {string}
 */
export const setToken = (token: string) => {
  if (!token) {
    return;
  }
  return setStorageSync('TOKEN', token);
};

/**
 *  获取本地openid
 * @type {string}
 */
export const getToken = () => {
  return getStorageSync('TOKEN');
};

/**
 *  删除传播人openid
 * @type {string}
 */
export const removeToken = () => {
  return removeStorageSync('TOKEN');
};

/**
 *  设置微信登录获取的code
 * @type {string}
 */
export const setWxCode = (token: string) => {
  if (!token) {
    return;
  }
  return setStorageSync('WXCODE', token);
};

/**
 *  获取本地openid
 * @type {string}
 */
export const getWxCode = () => {
  return getStorageSync('WXCODE');
};

/**
 *  删除传播人openid
 * @type {string}
 */
export const removeWxCode = () => {
  return removeStorageSync('WXCODE');
};

